home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V2 / 6.1 - MyStarter / CDragPane.c next >
Text File  |  1991-08-24  |  2KB  |  99 lines

  1. /************************************************************/
  2. /*                                                            */
  3. /*    CDragPane Code from Chapter Six of                        */
  4. /*                                                            */
  5. /*        *** The Macintosh Programming Primer ***            */
  6. /*                                                            */
  7. /*    Copyright 1990, Dave Mark                                */
  8. /*                                                            */
  9. /*    This program demonstrates specific Mac programming        */
  10. /*    techniques.                                                */
  11. /*                                                            */
  12. /************************************************************/
  13.  
  14. #include "CStarterPane.h"
  15. #include "CDragPane.h"
  16.  
  17. Boolean        gIsScrolling = FALSE;
  18.  
  19.  
  20. /******************************** IDragPane *********/
  21.  
  22. void CDragPane::IDragPane( Point            corner,
  23.                             int                height,
  24.                             int                width,
  25.                             int                patNum,
  26.                             CView            *anEnclosure,
  27.                             CBureaucrat        *aSupervisor )
  28. {
  29.     LongRect r;
  30.     
  31.     /* Restrict the pane to be within the bounds of the panorama. */
  32.     
  33.     ((CPanorama *)anEnclosure)->GetBounds(&r);
  34.     
  35.     if ((corner.h + width) > r.right)
  36.         corner.h -= corner.h + width - r.right;
  37.         
  38.     if ((corner.v + height) > r.bottom)
  39.         corner.v -= corner.v + height - r.bottom;
  40.  
  41.     IPane( anEnclosure, aSupervisor, width, height,
  42.                     corner.h, corner.v, sizFIXEDSTICKY, sizFIXEDSTICKY );
  43.                     
  44.     patNumber = patNum;
  45.     
  46.     SetWantsClicks( TRUE );
  47.     Refresh();
  48. }
  49.  
  50.  
  51. /******************************** Draw *********/
  52.  
  53. void CDragPane::Draw( Rect *rPtr )
  54. {
  55.     if ( ! gIsScrolling )
  56.     {
  57.         Prepare();
  58.         
  59.         switch( patNumber )
  60.         {
  61.             case 0:
  62.                 PenPat( ltGray );
  63.                 break;
  64.             case 1:
  65.                 PenPat( gray );
  66.                 break;
  67.             case 2:
  68.                 PenPat( dkGray );
  69.                 break;
  70.             default:
  71.                 PenPat( black );
  72.                 break;
  73.         }
  74.         
  75.         PaintRect( rPtr );
  76.     }
  77. }
  78.  
  79.  
  80. /******************************** DoClick *********/
  81.  
  82. void CDragPane::DoClick( Point hitPt, short modifierKeys, long when )
  83. {
  84.     Rect    r;
  85.     Rect    endLocation;
  86.     LongRect    longR;
  87.     
  88.     /*r = frame;   Old  */
  89.     FrameToQDR( &frame, &r );/*NEW*/
  90.     EraseRect( &r );
  91.     QDToLongRect(&r,&longR);
  92.     FrameToEnclR(&longR);
  93.     LongToQDRect( &longR, &r );
  94.  
  95.     ((CStarterPane *)itsEnclosure)->DoDrag( width, height,
  96.                                     hitPt, r, &endLocation );    
  97.                                     
  98.     Place(endLocation.left, endLocation.top, TRUE);    
  99. }